package com.cloud.system.api.mapper;

import com.cloud.system.api.bean.UnitPowerBean;
import com.cloud.system.api.bean.UnitPowerCriteriaBean;
import com.cloud.system.api.entity.UnitPower;
import com.cloud.system.api.provider.PowerPageProvider;
import com.cloud.system.api.provider.SuperviseBeanPageProvider;
import com.cloud.system.common.utils.BaseMapperHelper;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

public interface UnitPowerMapper extends BaseMapperHelper<UnitPower> {

//    @Select("select * from unit_power where unit_id = #{unitId}")
    @SelectProvider(type = PowerPageProvider.class, method = "listUnitPowerPage")
    @Results({
            @Result(property = "powerId",column = "power_id",javaType = Integer.class),
            @Result(property = "powerName", column = "power_name", javaType = String.class),
            @Result(property = "powerTypeId", column = "power_type_id", javaType = String.class),
            @Result(property = "powerTypeName", column = "power_type_name", javaType = String.class),
            @Result(property = "isInvolveCriminal", column = "is_involve_criminal", javaType = Integer.class),
            @Result(property = "powerStateId", column = "power_state_id", javaType = String.class),
            @Result(property = "powerStateName", column = "power_state_name", javaType = String.class),
            @Result(property = "effectiveDate", column = "effective_date", javaType = Date.class),
            @Result(property = "expiredDate", column = "expired_date", javaType = Date.class),
            @Result(property = "unitId", column = "unit_id", javaType = Long.class),
            @Result(property = "unitName", column = "unit_name", javaType = String.class),
            @Result(property = "isPublic", column = "is_public", javaType = Integer.class),
    })
    List<UnitPowerBean> listUnitPowerPage(UnitPowerCriteriaBean unitPowerCriteriaBean);

    @Insert("insert into unit_power(power_name,power_type_id,power_type_name,is_involve_criminal,power_state_id,power_state_name,effective_date,expired_date,unit_id,unit_name,is_public,create_human_id,create_human,create_method,unit_code) values(#{powerName},#{powerTypeId},#{powerTypeName}," +
            "#{isInvolveCriminal},#{powerStateId},#{powerStateName},#{effectiveDate},#{expiredDate},#{unitId},#{unitName},#{isPublic},#{createHumanId},#{createHuman},#{createMethod},#{unitCode}) ")
    @Options(useGeneratedKeys = true, keyProperty = "powerId")
    Integer insertUnitPower(UnitPower unitPower);

    @Select("select * from unit_power where power_id = #{powerId}")
    @Results({
            @Result(property = "powerId",column = "power_id",javaType = Integer.class),
            @Result(property = "powerName", column = "power_name", javaType = String.class),
            @Result(property = "powerTypeId", column = "power_type_id", javaType = String.class),
            @Result(property = "powerTypeName", column = "power_type_name", javaType = String.class),
            @Result(property = "isInvolveCriminal", column = "is_involve_criminal", javaType = Integer.class),
            @Result(property = "powerStateId", column = "power_state_id", javaType = String.class),
            @Result(property = "powerStateName", column = "power_state_name", javaType = String.class),
            @Result(property = "effectiveDate", column = "effective_date", javaType = Date.class),
            @Result(property = "expiredDate", column = "expired_date", javaType = Date.class),
            @Result(property = "unitId", column = "unit_id", javaType = Long.class),
            @Result(property = "unitName", column = "unit_name", javaType = String.class),
            @Result(property = "isPublic", column = "is_public", javaType = Integer.class),
    })
    UnitPowerBean loadPowerById(@Param("powerId") Integer powerId);
}